/*
 * @Author: leox_tian
 * @Date: 2021-07-30 13:06:02
 * @Description: mian.cc
 */
#include <algorithm>
#include <cstring>
#include <iostream>

#include "linefit.h"
using namespace std;

int main(void) {
  LineFit linefit;
  vector<float> X;
  vector<float> Y;

  cout << "一次多项式:y=5+7x" << endl;
  for (size_t i = 1; i <= 10; i++) {
    X.emplace_back(i);
    Y.emplace_back(5 + 7 * i + rand()%1) ;
  }
  int orders = 1;
  cout << linefit.LeastSquareFitBeeline(X, Y).transpose() << endl;
  cout << linefit.LeastSquareSVDMethod(X, Y, orders).transpose() << endl;
  cout << linefit.LeastSquareQRMethod(X, Y, orders).transpose() << endl;
  cout << linefit.LeastSquareLDLTMethod(X, Y, orders).transpose() << endl;
  cout << linefit.LeastSquareNormalMethod(X, Y, orders).transpose() << endl;

  cout << "\n二次多项式:y=3+x+2x^2" << endl;
  X.clear();
  Y.clear();
  for (size_t i = 1; i <= 5; i++) {
    X.emplace_back(i);
    Y.emplace_back(3 + i + 2 * i * i);
  }
  orders = 2;
  cout << linefit.LeastSquareFitCurve(X, Y).transpose() << endl;
  cout << linefit.LeastSquareSVDMethod(X, Y, orders).transpose() << endl;
  cout << linefit.LeastSquareQRMethod(X, Y, orders).transpose() << endl;
  cout << linefit.LeastSquareLDLTMethod(X, Y, orders).transpose() << endl;
  cout << linefit.LeastSquareNormalMethod(X, Y, orders).transpose() << endl;

  return 0;
}